import { defHttp } from '/@/utils/http/axios';
import { GetRoleListResponseModel, RoleModel } from './model/roleModel';
import { PermissionModel } from './model/permissionModel';
// 定义请求地址的枚举
enum Api {
  GetRoleList = '/admin/acl/role',
  RemoveRole = '/admin/acl/role/remove',
  SaveRole = '/admin/acl/role/save',
  UpdateRole = '/admin/acl/role/update',
  AssignRole = '/admin/acl/permission/doAssign',
  GetAssignRole = '/admin/acl/permission/toAssign',
}

export const getRoleListApi = (page: number, limit: number) => {
  return defHttp.get<GetRoleListResponseModel>({
    url: Api.GetRoleList,
    params: `/${page}/${limit}`,
  });
};

export const saveRoleApi = (role: RoleModel) => {
  return defHttp.post<null>({
    url: Api.SaveRole,
    data: role,
  });
};

export const assignRoleApi = (roleId: string, permissionId: string[]) => {
  return defHttp.post<null>({
    url: Api.AssignRole,
    params: `?roleId=${roleId}&permissionId=${permissionId}`,
  });
};

export const getAssignRoleApi = (roleId: string) => {
  return defHttp.get<PermissionModel>({
    url: Api.GetAssignRole,
    params: `/${roleId}`,
  });
};
